Python/Python Mcq Set 11 Sample Test,Sample questions

Question:
 If b is a dictionary, what does any(b) do?

1. Returns True if any key of the dictionary is true

2. Returns False if dictionary is empty

3.Returns True if all keys of the dictionary are true

4.Method any() doesn’t exist for dictionary

Posted Date:-2021-12-31 10:15:40


Question:
 What will be the output of the following Python code snippet?

>>>import collections
>>> a=collections.Counter([1,1,2,3,3,4,4,4])
>>> a

1.{1,2,3,4}

2.Counter({4, 1, 3, 2})

3.Counter({4: 3, 1: 2, 3: 2, 2: 1})

4. {4: 3, 1: 2, 3: 2, 2: 1}

Posted Date:-2021-12-31 09:59:15


Question:
 What will be the output of the following Python code snippet?

a={}
a['a']=1
a['b']=[2,3,4]
print(a)

1.Exception is thrown

2. {‘b’: [2], ‘a’: 1}

3.{‘b’: [2], ‘a’: [3]}

4.{‘b’: [2, 3, 4], ‘a’: 1}

Posted Date:-2021-12-31 09:58:50


Question:
 What will be the output of the following Python code?

>>> a={1:"A",2:"B",3:"C"}
>>> a.items()

1.Syntax error

2.dict_items([(‘A’), (‘B’), (‘C’)])

3.dict_items([(1,2,3)])

4.dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])

Posted Date:-2021-12-31 09:38:29


Question:
 What will be the output of the following Python code?

>>> a={}
>>> a.fromkeys([1,2,3],"check")

1.Syntax error

2.{1:”check”,2:”check”,3:”check”}

3. “check”

4. {1:None,2:None,3:None}

Posted Date:-2021-12-31 10:09:38


Question:
 What will be the output of the following Python code?

>>> b={}
>>> all(b)

1.{ }

2.False

3.True

4. An exception is thrown

Posted Date:-2021-12-31 10:10:12


Question:
 What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}
b=a.copy()
b[2]="D"
print(a)

1.Error, copy() method doesn’t exist for dictionaries

2.{1: ‘A’, 2: ‘B’, 3: ‘C’}

3. {1: ‘A’, 2: ‘D’, 3: ‘C’}

4.“None” is printed

Posted Date:-2021-12-31 09:35:59


Question:
 What will be the output of the following Python function?

any([2>8, 4>2, 1>2])

1.Error

2. True

3. False

4. 4>2

Posted Date:-2021-12-31 10:46:23


Question:
 Which of the following is not a declaration of the dictionary?

1.{1: ‘A’, 2: ‘B’}

2. dict([[1,”A”],[2,”B”]])

3.{1,”A”,2”B”}

4.{ }

Posted Date:-2021-12-31 09:33:09


Question:
If a is a dictionary with some key-value pairs, what does a.popitem() do?

1.Removes an arbitrary element

2. Removes all the key-value pairs

3.Removes the key-value pair for the key given as an argument

4. Invalid method for dictionary

Posted Date:-2021-12-31 09:54:22


Question:
Suppose d = {“john”:40, “peter”:45}, what happens when we try to retrieve a value using the expression d[“susan”]?

1. Since “susan” is not a value in the set, Python raises a KeyError exception

2.It is executed fine and no exception is raised, and it returns None

3. Since “susan” is not a key in the set, Python raises a KeyError exception

4.Since “susan” is not a key in the set, Python raises a syntax error

Posted Date:-2021-12-31 09:31:52


Question:
What will be the output of the following Python code snippet?

>>> a={1:"A",2:"B",3:"C"}
>>> del a

1.method del doesn’t exist for the dictionary

2. del deletes the values in the dictionary

3.del deletes the entire dictionary

4. del deletes the keys in the dictionary

Posted Date:-2021-12-31 09:53:50


Question:
What will be the output of the following Python code snippet?

>>> import collections
>>> a=collections.Counter([2,2,3,3,3,4])
>>> b=collections.Counter([2,2,3,4,4])
>>> a|b

1.Counter({3: 3, 2: 2, 4: 2})

2. Counter({2: 2, 3: 1, 4: 1})

3.Counter({3: 2})

4.Counter({4: 1})

Posted Date:-2021-12-31 10:01:50


Question:
What will be the output of the following Python code snippet?

>>> import collections
>>> a=collections.Counter([3,3,4,5])
>>> b=collections.Counter([3,4,4,5,5,5])
>>> a&b

1.Counter({3: 12, 4: 1, 5: 1})

2. Counter({3: 1, 4: 1, 5: 1})

3.Counter({4: 2})

4. Counter({5: 1})

Posted Date:-2021-12-31 10:02:16


Question:
What will be the output of the following Python code snippet?

>>>import collections
>>> b=collections.Counter([2,2,3,4,4,4])
>>> b.most_common(1)

1.Counter({4: 3, 2: 2, 3: 1})

2.{3:1}

3.{4:3}

4. [(4, 3)]

Posted Date:-2021-12-31 09:59:40


Question:
What will be the output of the following Python code snippet?

a = {}
a[1] = 1
a['1'] = 2
a[1.0]=4
count = 0
for i in a:
    count += a[i]
print(count)

1.An exception is thrown

2. 3

3.6

4. 2

Posted Date:-2021-12-31 09:57:43


Question:
What will be the output of the following Python code snippet?

a = {}
a[1] = 1
a['1'] = 2
a[1]=a[1]+1
count = 0
for i in a:
    count += a[i]
print(count)

1. 1

2.2

3. 4

4. Error, the keys can’t be a mixture of letters and numbers

Posted Date:-2021-12-31 09:55:19


Question:
What will be the output of the following Python code snippet?

a={1:"A",2:"B",3:"C"}
a.setdefault(4,"D")
print(a)

1. {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’}

2.None

3.Error

4.[1,3,6,10]

Posted Date:-2021-12-31 09:35:03


Question:
What will be the output of the following Python code snippet?

a={1:"A",2:"B",3:"C"}
print(a.get(1,4))

1. 1

2.A

3.4

4.Invalid syntax for get method

Posted Date:-2021-12-31 09:33:38


Question:
What will be the output of the following Python code snippet?

a={1:"A",2:"B",3:"C"}
print(a.get(5,4))

1.Error, invalid syntax

2. A

3.5

4.4

Posted Date:-2021-12-31 09:34:03


Question:
What will be the output of the following Python code snippet?

a={1:"A",2:"B",3:"C"}
print(a.setdefault(3))

1.{1: ‘A’, 2: ‘B’, 3: ‘C’}

2.C

3.{1: 3, 2: 3, 3: 3}

4.No method called setdefault() exists for dictionary

Posted Date:-2021-12-31 09:34:33


Question:
What will be the output of the following Python code snippet?

numbers = {}
letters = {}
comb = {}
numbers[1] = 56
numbers[3] = 7
letters[4] = 'B'
comb['Numbers'] = numbers
comb['Letters'] = letters
print(comb)

1.Error, dictionary in a dictionary can’t exist

2. ‘Numbers’: {1: 56, 3: 7}

3.{‘Numbers’: {1: 56}, ‘Letters’: {4: ‘B’}}

4.{‘Numbers’: {1: 56, 3: 7}, ‘Letters’: {4: ‘B’}}

Posted Date:-2021-12-31 09:56:25


Question:
What will be the output of the following Python code snippet?

test = {1:'A', 2:'B', 3:'C'}
del test[1]
test[1] = 'D'
del test[2]
print(len(test))

1.0

2.2

3. Error as the key-value pair of 1:’A’ is already deleted

4.1

Posted Date:-2021-12-31 09:57:14


Question:
What will be the output of the following Python code snippet?

test = {1:'A', 2:'B', 3:'C'}
test = {}
print(len(test))

1. 0

2.None

3. 3

4.An exception is thrown

Posted Date:-2021-12-31 09:56:48


Question:
What will be the output of the following Python code snippet?

total={}
def insert(items):
    if items in total:
        total[items] += 1
    else:
        total[items] = 1
insert('Apple')
insert('Ball')
insert('Apple')
print (len(total))

1. 3

2. 1

3. 2

4. 0

Posted Date:-2021-12-31 09:54:49


Question:
What will be the output of the following Python code?

>>> a=dict()
>>> a[1]

1.An exception is thrown since the dictionary is empty

2. ‘ ‘

3. 1

4. 0

Posted Date:-2021-12-31 10:29:48


Question:
What will be the output of the following Python code?

>>> a={'B':5,'A':9,'C':7}
>>> sorted(a)

1. [‘A’,’B’,’C’]

2.[‘B’,’C’,’A’]

3.[5,7,9]

4.[9,5,7]

Posted Date:-2021-12-31 10:07:02


Question:
What will be the output of the following Python code?

>>> a={"a":1,"b":2,"c":3}
>>> b=dict(zip(a.values(),a.keys()))
>>> b

1.{‘a’: 1, ‘b’: 2, ‘c’: 3}

2.An exception is thrown

3.{‘a’: ‘b’: ‘c’: }

4. {1: ‘a’, 2: ‘b’, 3: ‘c’}

Posted Date:-2021-12-31 10:18:23


Question:
What will be the output of the following Python code?

>>> a={i: 'A' + str(i) for i in range(5)}
>>> a

1. An exception is thrown

2.{0: ‘A0’, 1: ‘A1’, 2: ‘A2’, 3: ‘A3’, 4: ‘A4’}

3.{0: ‘A’, 1: ‘A’, 2: ‘A’, 3: ‘A’, 4: ‘A’}

4.{0: ‘0’, 1: ‘1’, 2: ‘2’, 3: ‘3’, 4: ‘4’}

Posted Date:-2021-12-31 10:29:15


Question:
What will be the output of the following Python code?

>>> a={i: i*i for i in range(6)}
>>> a

1.Dictionary comprehension doesn’t exist

2. {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36}

3.{0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25}

4.{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

Posted Date:-2021-12-31 10:07:28


Question:
What will be the output of the following Python code?

>>> import collections
>>> a=collections.OrderedDict((str(x),x) for x in range(3))
>>> a

1.{‘2’:2, ‘0’:0, ‘1’:1}

2.OrderedDict([(‘0’, 0), (‘1’, 1), (‘2’, 2)])

3.An exception is thrown

4. ‘ ‘

Posted Date:-2021-12-31 10:42:37


Question:
What will be the output of the following Python code?

>>> import collections
>>> a=dict()
>>> a=collections.defaultdict(int)
>>> a[1]

1.1

2.0

3.An exception is thrown

4. ‘ ‘

Posted Date:-2021-12-31 10:30:14


Question:
What will be the output of the following Python code?

>>> import collections
>>> a=dict()
>>> a=collections.defaultdict(str)
>>> a['A']

1.An exception is thrown since the dictionary is empty

2.‘ ‘

3. ‘A’

4.0

Posted Date:-2021-12-31 10:30:42


Question:
What will be the output of the following Python code?

>>> import collections
>>> b=dict()
>>> b=collections.defaultdict(lambda: 7)
>>> b[4]

1.4

2.0

3.An exception is thrown

4. 7

Posted Date:-2021-12-31 10:31:31


Question:
What will be the output of the following Python code?

>>> import collections
>>> b=dict()
>>> b=collections.defaultdict(lambda: 7)
>>> b[4]

1.4

2.0

3.An exception is thrown

4. 7

Posted Date:-2021-12-31 10:31:53


Question:
What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}
a.clear()
print(a)

1.None

2.{ None:None, None:None, None:None}

3. {1:None, 2:None, 3:None}

4.{ }

Posted Date:-2021-12-31 09:36:23


Question:
What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}
b={4:"D",5:"E"}
a.update(b)
print(a)

1.{1: ‘A’, 2: ‘B’, 3: ‘C’}

2.Method update() doesn’t exist for dictionaries

3. {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}

4. {4: ‘D’, 5: ‘E’}

Posted Date:-2021-12-31 09:35:28


Question:
What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}
for i in a:
    print(i,end=" ")

1.1 2 3

2. ‘A’ ‘B’ ‘C’

3. 1 ‘A’ 2 ‘B’ 3 ‘C’

4.Error, it should be: for i in a.items():

Posted Date:-2021-12-31 09:38:04


Question:
What will be the output of the following Python code?

a={1:5,2:3,3:4}
a.pop(3)
print(a)

1.{1: 5}

2.{1: 5, 2: 3}

3.Error, syntax error for pop() method

4.{1: 5, 3: 4}

Posted Date:-2021-12-31 09:37:14


Question:
What will be the output of the following Python code?

a={1:5,2:3,3:4}
print(a.pop(4,9))

1.9

2.3

3.Too many arguments for pop() method

4.4

Posted Date:-2021-12-31 09:37:41


Question:
What will be the output of the following Python code?

a={}
a[2]=1
a[1]=[2,3,4]
print(a[1][1])

1.[2,3,4]

2.3

3. 2

4.An exception is thrown

Posted Date:-2021-12-31 10:06:33


Question:
What will be the output of the following Python code?

count={}
count[(1,2,4)] = 5
count[(4,2,1)] = 7
count[(1,2)] = 6
count[(4,2,1)] = 2
tot = 0
for i in count:
    tot=tot+count[i]
print(len(count)+tot)

1.25

2.17

3.16

4. Tuples can’t be made keys of a dictionary

Posted Date:-2021-12-31 10:03:07


Question:
What will be the output of the following Python expression?

round(4.5676,2)?

1. 4.5

2.4.6

3. 4.57

4.4.56

Posted Date:-2021-12-31 10:45:31


Question:
What will be the output of the following Python function?

all(3,0,4.2)

1. True

2.False

3.Error

4. 0

Posted Date:-2021-12-31 10:57:32


Question:
What will be the output of the following Python function?

all([2,4,0,6])

1. Error

2.True

3. False

4.0

Posted Date:-2021-12-31 10:44:54


Question:
What will be the output of the following Python function?

import math
abs(math.sqrt(25))

1. Error

2. -5

3.5

4.5.0

Posted Date:-2021-12-31 10:50:30


Question:
What will be the output of the following Python function?

sum(2,4,6)
sum([1,2,3])

1.Error, 6

2.12, Error

3.12, 6

4.Error, Error

Posted Date:-2021-12-31 10:53:46


Question:
Which of the following isn’t true about dictionary keys?

1. More than one key isn’t allowed

2.Keys must be immutable

3.Keys must be integers

4.When duplicate keys encountered, the last assignment wins

Posted Date:-2021-12-31 09:36:52


Question:
Which of the statements about dictionary values if false?

1. More than one key can have the same value

2.The values of the dictionary can be accessed as dict[key]

3.Values of a dictionary must be unique

4.Values of a dictionary can be a mixture of letters and numbers

Posted Date:-2021-12-31 09:41:06


Question:
Which of these about a dictionary is false?

1.The values of a dictionary can be accessed using keys

2.The keys of a dictionary can be accessed using values

3.Dictionaries aren’t ordered

4.Dictionaries are mutable

Posted Date:-2021-12-31 09:32:37


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
  50. Python MCQ
  51. Python MCQ Questions with Answer
  52. Test
  53. python mcq question and answer
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!